// https://leetcode.cn/problems/plus-one/
#include <vector>
#include <iostream>

using namespace std;

class Solution {
public:
    vector<int> plusOne(vector<int>& digits) {
		int len = digits.size();
		int tmp = digits[len - 1] + 1;
		if(tmp < 10){
			digits[len - 1] = tmp;
			return digits;
		}
		digits[len - 1] = 0;
		int flag = 1;
		for(int i = 1; i < len; i++){
			int tmp = digits[len - 1 - i] + flag;
			if(tmp >= 10){
				digits[len - 1 - i] = tmp - 10;
				flag = 1;
			}else{
				digits[len - 1 - i] = tmp;
				flag = 0;
				break;
			}
		}
		if(flag){
			digits.insert(digits.begin(), 1);
		}
		return digits;
    }
};

int main(){
	Solution so;
	vector<int> digits = {7,2,8,5,0,9,1,2,9,5,3,6,6,7,3,2,8,4,3,7,9,5,7,7,4,7,4,9,4,7,0,1,1,1,7,4,0,0,6};
	// vector<int> digits = {3,9,9,9};
	vector<int> res = so.plusOne(digits);
	for(auto i : res){
		cout << i << ",";
	}
	cout << endl;
	return 0;
}